package org.platform.processor.diagnose.job;

import com.mc.mic.core.log.bus.BusLogPusher;
import com.mc.mic.core.log.frame.LogBo;
import lombok.extern.slf4j.Slf4j;
import org.platform.constant.LogType;
import org.platform.mo.bussmo.log.TestDiagnoseResultMqBO;
import org.platform.mo.csmo.common.FD_TestDiagnoseResult;
import org.quartz.InterruptableJob;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 将 测试诊断结果 推送到客服端
 *
 * @author FengJie
 * @date 2018/7/20
 */
@Slf4j
public class PromoteTestDiagnoseResultJob implements InterruptableJob {
    public static final String JOB_KEY = "PromoteTestDiagnoseResultJob";
    public static final String DATA_KEY = "diagnoseResult";
    @Autowired
    private BusLogPusher mqLog;

    @Override
    public void interrupt() {

    }

    @Override
    public void execute(JobExecutionContext context) {
        try {
            JobDataMap dataMap = context.getMergedJobDataMap();
            String jsonResult = (String) dataMap.get(DATA_KEY);
            mqLog.log(new LogBo<>(LogType.TEST_RESULT, new TestDiagnoseResultMqBO(new FD_TestDiagnoseResult(jsonResult))));
        } catch (Exception e) {
            log.error("测试诊断结果推动job:【{}】发生错误,异常信息", JOB_KEY, e);
        }
    }
}
